package com.front.web.controller;

import java.security.KeyPair;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.front.common.JCryptionUtil;
import com.google.gson.Gson;

@Controller
public class CommonController  extends BaseController{

	/**
	 * 
	 * @param request
	 * @param resp
	 * @throws Exception
	 */
	@RequestMapping(value = "/common/getFrontCryption", method = RequestMethod.GET)
	public void getBetCryption(HttpServletRequest request, HttpServletResponse resp) throws Exception 
	{ 
		JCryptionUtil jCryptionUtil = new JCryptionUtil();  
		KeyPair keys  = jCryptionUtil.generateKeypair(512);  
		request.getSession().setAttribute("keys", keys);    
		String e = JCryptionUtil.getPublicKeyExponent(keys);  
		String n = JCryptionUtil.getPublicKeyModulus(keys);  
		String md = String.valueOf(JCryptionUtil.getMaxDigits(512)); 
		Map<String,Object>conf =  new HashMap<String, Object>();
		conf.put("e", e);
		conf.put("n", n);
		conf.put("maxdigits", md);
		this.renderJson(resp,new Gson().toJson(conf));
	}
}
